﻿@using thousandClear.Areas.Admin.Models;
@model List<OrderModel>
@{
    ViewBag.Title = "订单管理";
    Layout = "~/Areas/Admin/Views/Shared/_Admin.cshtml";
}
<div id="divMain" style="width:100%; position:fixed; left:0px; top:0px; z-index:99999; background-color:white; filter:alpha(opacity=80);
	-moz-opacity:0.8;
	-khtml-opacity: 0.8;
	opacity: 0.8;">

    <img src="~/Statics/Images/Activity/load.gif" style="position:fixed; width:10%; left:40%; top:40%" />
</div>

<div id="app">
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">后台管理</strong> / <small>@ViewBag.Title</small></div>
    </div>

    <div class="am-g" style="width:1100px;">
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>订单号：</label>
                <input type="text" class="am-input-sm" v-model="sn" />
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>状态：</label>
                <select v-model="status">
                    <option value="">全部</option>
                    <option value="4">未付款</option>
                    <option value="1">已付款</option>
                    <option value="2">已取消</option>
                    <option value="3">已冻结</option>
                    <option value="5">已分配</option>
                    <option value="6">已完成</option>
                    <option value="0">已续约</option>
                </select>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>服务类型：</label>
                <select v-model="cType">
                    <option value="">全部</option>
                    <option value="1">日常服务</option>
                    <option value="2">单次体验</option>
                    <option value="3">单次服务</option>
                    <option value="4">体验活动</option>
                </select>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>客户编号：</label>
                <input type="text" class="am-input-sm" v-model="cNo" />
            </div>

        </div>

        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>开卡类型：</label>
                <select v-model="cardTy">
                    <option value="">全部</option>
                    <option value="2">一月2次</option>
                    <option value="4">一月4次</option>
                    <option value="8">一月8次</option>
                    <option value="15">一月15次</option>

                </select>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>开卡时长：</label>
                <select v-model="cardMouth">
                    <option value="">全部</option>
                    <option value="1">1个月</option>
                    <option value="3">3个月</option>
                    <option value="6">6个月</option>
                    <option value="12">12个月</option>

                </select>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>赠送时长：</label>
                <select v-model="addTime">
                    <option value="">全部</option>
                    <option value="1">1个月</option>
                    <option value="2">2个月</option>
                    <option value="3">3个月</option>
                </select>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>服务管家：</label>
                <select v-model="auntPer">

                    <option value="">全部</option>
                    @foreach (var tt in ViewBag.Auntlist)
                    {
                        <option value="@tt.OATID">@tt.oatName</option>
                    }

                </select>
            </div>
        </div>


        <div class="am-u-sm-12 am-u-md-5">
            <div class="am-form-group">
                <label>日常总次数（小于，等于）：</label>
                <input type="number" class="am-input-sm" v-model="richangNo" />
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-5">
            <div class="am-form-group">
                <label>日常剩余总次数（小于，等于）：</label>
                <input type="number" class="am-input-sm" v-model="richangshengyuNo" />
            </div>

        </div>
        <div class="am-u-sm-12 am-u-md-5">
            <div class="am-form-group">
                <label>专项总次数（小于，等于）：</label>
                <input type="number" class="am-input-sm" v-model="chuanxiangNo" />
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-5">
            <div class="am-form-group">
                <label>专项剩余总次数（小于，等于）：</label>
                <input type="number" class="am-input-sm" v-model="chuanxiangshengyuNo" />
            </div>

        </div>


        <div class="am-u-sm-12 am-u-md-12">
            <button class="am-btn am-btn-primary" v-on:click="search">查询</button>
            @if (ViewBag.level != "2")
            {
                <button class="am-btn am-btn-primary" data-am-modal="{target: '#doc-modal-2', closeViaDimmer: 0, width: 800, height: 600}" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only">新增</button>
                <a href="../admin/export/orderlist" target="_blank" class="am-btn am-btn-primary">导出订单Excel</a>
            }
        </div>
        <div class="am-g">
            <div class="am-u-sm-12" id="divMain" style="overflow-x: auto;">
                <table class="am-table am-table-striped am-table-hover table-main" style="width:2100px;">
                    <thead>
                        <tr>
                            <th>下单时间</th>
                            <th>订单号</th>
                            <th>状态</th>
                            <th>服务类型</th>
                            <th>客户编号</th>
                            <th>卖家昵称</th>
                            <th>单价</th>
                            <th>数量</th>
                            <th>总价</th>
                            <th>开卡类型</th>
                            <th>开卡时长</th>
                            <th>赠送时长</th>
                            <th>日常总次数</th>
                            <th>日常剩余次数</th>
                            <th>专项总次数</th>
                            <th>专项剩余次数</th>
                            <th>服务管家</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (OrderModel item in Model)
                        {
                            <tr>
                                <td>@item.CreatedDate.ToString("yyyy - MM - dd HH: mm")</td>
                                <td>@item.toSerialNo</td>
                                <td>
                                    @if (item.RowStatus == 1)
                                    {
                                        <span>已付款</span>
                                    }
                                    @if (item.RowStatus == 2)
                                    {
                                        <span>已取消</span>
                                    }
                                    @if (item.RowStatus == 3)
                                    {
                                        <span>已冻结</span>
                                    }
                                    @if (item.RowStatus == 4)
                                    {
                                        <span>未付款</span>
                                    }
                                    @if (item.RowStatus == 5)
                                    {
                                        <span>已分配</span>
                                    }
                                    @if (item.RowStatus == 6)
                                    {
                                        <span>已完成</span>
                                    }
                                    @if (item.RowStatus == 7)
                                    {
                                        <span>已续约</span>
                                    }
                                </td>
                                <td>@item.ogsDesc</td>
                                <td>@item.oasno</td>
                                <td>@item.ocNicName</td>
                                <td>@item.toTotalRate</td>
                                <td>@item.toGoodNum</td>
                                <td>@(item.toTotalRate * item.toGoodNum)</td>
                                <td>一月 @item.ogsTimeMonth 次</td>
                                <td>@item.ogsSignTime 个月</td>

                                @if (item.ogsTimeMonth > 1)
                                {
                                    <td>@(((item.ogsTime - item.ogsTimeMonth * item.ogsSignTime) / item.ogsTimeMonth) < 0 ? 0 : ((item.ogsTime - item.ogsTimeMonth * item.ogsSignTime) / item.ogsTimeMonth)) 个月</td>
                                }

                                @if (item.ogsTimeMonth <= 1)
                                {
                                    <td>0个月</td>
                                }



                                <td>@(item.ogsTime + item.yue)</td>
                                <td>@(item.toTime)</td>
                                <td>@(item.ogsSeqNum + item.toZengSongLieji)</td>
                                <td>@item.toSeqNum</td>
                                <td>@item.AuntName</td>


                                <td>
                                    @if (ViewBag.uid == "02" || ViewBag.level != "2")
                                    {


                                        if (item.RowStatus == 1)
                                        {
                                            <div class="am-btn-toolbar" style="float:left; margin-left:5px;">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <a v-on:click="giveOrder('@item.toSerialNo')" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0, width: 800, height: 600}" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span>分配管家</a>
                                                </div>
                                            </div>
                                        }
                                        if (item.RowStatus == 5)
                                        {
                                            <div class="am-btn-toolbar" style="float:left; margin-left:5px;">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <a v-on:click="giveOrder('@item.toSerialNo')" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0, width: 800, height: 600}" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span>修改管家</a>
                                                </div>
                                            </div>
                                        }
                                        if (ViewBag.level != "2")
                                        {

                                            <div class="am-btn-toolbar" style="float:left;">
                                                <div class="am-btn-group am-btn-group-xs">

                                                    <a onclick="getOrderDetail(@item.toSerialNo,@item.TOID)" data-am-modal="{target: '#doc-modal-3', closeViaDimmer: 0, width: 800, height: 600}" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span>修改/续约/删除</a>
                                                </div>
                                            </div>
                                        }
                                    }
                                    <div class="am-btn-toolbar" style="float:left;  margin-left:5px;">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a href="~/admin/order/detail?toSerialNo=@item.toSerialNo" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span> 查看详情</a>
                                        </div>
                                    </div>


                                </td>

                            </tr>
                        }
                    </tbody>
                </table>
                <div class="am-cf">
                    &nbsp;&nbsp;共 {{totalCount}} 条记录, 每页 {{pageCount}} 条记录
                    <div class="am-fr">
                        <ul class="am-pagination">
                            <li style="width: 60px">
                                <input class="am-form-field" style="text-align:center" type="text" v-model="gotoPage" />
                            </li>
                            <li><a href="#" v-on:click="goto">GoTo &raquo;</a></li>
                            <li><a href="#" v-on:click="prev">&laquo; Prev</a></li>
                            <li><span>{{currentPage}}/{{totalPage}}</span></li>
                            <li><a href="#" v-on:click="next">Next &raquo;</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-2">
        <div class="am-modal-dialog" style="overflow-y:auto;">
            <div class="am-modal-hd">
                新增订单
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div class="am-modal-bd">
                <div class="am-g">
                    <div class="am-u-sm-12">
                        <div class="am-form-group">
                            <label>客户编号：</label>
                            <input type="text" class="am-input-sm" id="txtNos" />
                        </div>
                        <div class="am-form-group">
                            <label>选择产品：</label>
                            <select id="txtP">

                                @foreach (var tt in ViewBag.goodsList)
                                {
                                    <option value="@tt.OGSID">@tt.ogsDesc -- 1月 @tt.ogsTimeMonth 次 -- 面积 @tt.ogsArea -- 总次数 @tt.ogsTime 次 --赠送：@tt.ogsSeqNum 次 </option>
                                }

                            </select>
                        </div>
                        <div class="am-form-group">
                            <label>总价：</label>
                            <input type="text" class="am-input-sm" id="txtRate" />
                        </div>
                        <div class="am-form-group">
                            <label>开始日期：</label>
                            <input type="date" class="am-input-sm" id="txtDate" />
                        </div>
                        <div class="am-form-group">
                            <label>服务时间：</label>
                            <input type="time" class="am-input-sm" id="txtTime" value="09:00" />
                        </div>
                        <div class="am-form-group">
                            <label>日常剩余次数：</label>
                            <input type="text" class="am-input-sm" id="txtrichang" />
                        </div>
                        <div class="am-form-group">
                            <label>专项剩余次数：</label>
                            <input type="text" class="am-input-sm" id="txtzhuanxiang" />
                        </div>

                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-12">
                    <button class="am-btn am-btn-primary" onclick="onSubOgr()">新增订单</button>
                </div>
            </div>
        </div>
    </div>

    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
        <div class="am-modal-dialog" style="overflow-y:auto;">
            <div class="am-modal-hd">
                管家列表
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div class="am-modal-bd">
                <div class="am-g">
                    <div class="am-u-sm-12">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>姓名</th>
                                    <th>手机</th>
                                    <th>描述</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in ViewBag.Auntlist)
                                {
                                    <tr style="text-align:left;">
                                        <td>@item.OATID</td>
                                        <td>@item.oatName</td>
                                        <td>@item.oatPhone</td>
                                        <td>@item.oatDesc</td>
                                        <td>
                                            <div class="am-btn-group" data-am-button>
                                                <label class="am-btn am-btn-primary">
                                                    <input type="checkbox" name="doc-js-btn" value="@item.OATID"> 分配
                                                </label>
                                            </div>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-12">
                    <button class="am-btn am-btn-primary" v-on:click="giveAunt">分配管家</button>
                </div>
            </div>
        </div>
    </div>

    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-3">
        <div class="am-modal-dialog" style="overflow-y:auto;">
            <div class="am-modal-hd">
                更新/续约订单
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div class="am-modal-bd">
                <div class="am-g">
                    <div class="am-u-sm-12">
                        <div class="am-form-group">
                            <label>订单号：</label>
                            <span id="spOrder"></span>
                        </div>
                        <div class="am-form-group">
                            <label>订单ID：</label>
                            <span id="spOrderID"></span>
                        </div>
                        <div class="am-form-group">
                            <label>客户编号：</label>
                            <input type="text" class="am-input-sm" id="txtNosS" />
                        </div>

                        <div class="am-form-group">
                            <label>订单状态：</label>
                            <select id="txtStatus">
                                <option value="4">未付款</option>
                                <option value="1">已付款</option>
                                <option value="2">已取消</option>
                                <option value="3">已冻结</option>
                                <option value="5">已分配</option>
                                <option value="6">已完成</option>
                            </select>
                        </div>


                        <div class="am-form-group">
                            <label>选择产品：</label>
                            <select id="txtPS">

                                @foreach (var tt in ViewBag.goodsList)
                                {
                                    <option value="@tt.OGSID">@tt.ogsDesc -- 1月 @tt.ogsTimeMonth 次 -- 面积 @tt.ogsArea -- 总次数 @tt.ogsTime 次 --赠送：@tt.ogsSeqNum 次 </option>
                                }

                            </select>
                        </div>
                        <div class="am-form-group">
                            <label>总价：</label>
                            <input type="text" class="am-input-sm" id="txtRateS" />
                        </div>
                        <div class="am-form-group">
                            <label>开始日期：</label>
                            <input type="date" class="am-input-sm" id="txtDateS" />
                        </div>
                        <div class="am-form-group">
                            <label>结束日期：</label>
                            <input type="date" class="am-input-sm" id="txtEndDateS" />
                        </div>
                        <div class="am-form-group">
                            <label>服务时间：</label>
                            <input type="time" class="am-input-sm" id="txtTimeS" value="09:00" />
                        </div>
                        <div class="am-form-group">
                            <label>日常剩余次数：</label>
                            <input type="text" class="am-input-sm" id="txtrichangS" />
                        </div>
                        <div class="am-form-group">
                            <label>专项剩余次数：</label>
                            <input type="text" class="am-input-sm" id="txtzhuanxiangS" />
                        </div>

                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-12">
                    <button class="am-btn am-btn-primary" onclick="updateOrder()">修改订单</button>
                    <button class="am-btn am-btn-primary" onclick="GoToContiun()">续约</button>
                    <button class="am-btn am-btn-primary" onclick="deleteOrder()">删除</button>
                </div>
            </div>
        </div>
    </div>
</div>
@section Scripts{
    <script>

        $(function() {

            $("#divMain").css("height",$(window).height()+"px");
            closeLoading();
        });

        function showLoading(){

            $("#divMain").css("display","");
        }

        function closeLoading(){

            $("#divMain").css("display","none");
        }

        var model = new Vue({
            el: '#app',
            data: {
                totalCount: @ViewBag.TotalCount,
                currentPage: @ViewBag.CurrentPage,
                pageCount: @ViewBag.PageCount,
                gotoPage: @ViewBag.CurrentPage,
                totalPage: @ViewBag.TotalPage,
                mobile: '@ViewBag.Mobile',
                sn:'@ViewBag.SN',
                status:'@ViewBag.Status',
                cType:'@ViewBag.cType',
                cNo:'@ViewBag.cNo',
                cardTy:'@ViewBag.cardTy',
                cardMouth:'@ViewBag.cardMouth',
                addTime:'@ViewBag.addTime',
                auntPer:'@ViewBag.auntPer',
                richangNo:'@ViewBag.richangNo',
                richangshengyuNo:'@ViewBag.richangshengyuNo',
                chuanxiangNo:'@ViewBag.chuanxiangNo',
                chuanxiangshengyuNo:'@ViewBag.chuanxiangshengyuNo',
                order:'',
                aunt:[],
            },
            methods: {
                prev: function() {
                    var self = this;
                    if (self.currentPage <= 1)
                        return;

                    self.currentPage -= 1;
                    self.load();
                },
                next: function() {
                    var self = this;

                    if (self.currentPage >= self.totalPage)
                        return;

                    self.currentPage += 1;

                    self.load();
                },
                goto: function() {
                    var self = this;
                    self.currentPage = self.gotoPage;
                    self.load();
                },
                search: function() {
                    var self = this;
                    self.currentPage = 1;
                    self.load();
                },
                load: function() {
                    var self = this;
                    window.location.href = "../admin/order?page=" + self.currentPage + "&count=" + self.pageCount + "&sn=" + self.sn + "&mobile=" + self.mobile + "&status=" + self.status + "&cType=" + self.cType + "&cNo=" + self.cNo + "&cardTy=" + self.cardTy + "&cardMouth=" + self.cardMouth+ "&addTime=" + self.addTime+ "&auntPer=" + self.auntPer+ "&richangNo=" + self.richangNo+ "&richangshengyuNo=" + self.richangshengyuNo+ "&chuanxiangNo=" + self.chuanxiangNo+ "&chuanxiangshengyuNo=" + self.chuanxiangshengyuNo;
                },
                giveOrder: function(idx){
                    var self= this;
                    self.order=idx;
                },
                giveAunt:function(){

                    var self = this;

                    var aunt=this.aunt.toString();
                    var data = {
                        aunt:aunt,
                        order:self.order,
                    }
                    var c = confirm('确认分配吗?');
                    if (c) {
                        $.ajax({
                            type: "get",
                            data: data,
                            url: "Order/giveAunt",
                            contentType: "application/json",
                            success: function (data) {
                                alert("分配成功!");
                                window.location.reload();
                            },
                            error:function(a,b){
                                alert(a.status);
                            }

                        })


                    }
                    else {
                        return;
                    }


                }

            }
        });

        $(function() {
            var $cb = $('[name="doc-js-btn"]');
            $cb.on('change', function() {
                var checked = [];
                $cb.filter(':checked').each(function() {
                    checked.push(this.value);
                });
                model._data.aunt=checked;
            });




        });

        $('.admin-sidebar-order').addClass('current');

        function onSubOgr(){

            showLoading();

            var data1 = '{"txtNos":"'+$("#txtNos").val()+'","txtP":"'+$("#txtP").val()+'","txtRate":"'+$("#txtRate").val()+'","txtDate":"'+$("#txtDate").val()+'","txtTime":"'+$("#txtTime").val()+'","txtrichang":"'+$("#txtrichang").val()+'","txtzhuanxiang":"'+$("#txtzhuanxiang").val()+'"}';
            $.ajax({
                type: "POST",
                url: "../admin/Order/CreateOrder",
                contentType: "application/json",
                data: data1,
                success: function (responseData) {
                    var ss = responseData;

                    if(ss=="1"){
                        window.location.href="../admin/Order";
                    }
                }
            });
        }

        function getOrderDetail(obj,id){

            $("#spOrderID").text(id);

            var data1 = '{"order":"'+id.toString()+'"}';

            showLoading();
            $.ajax({
                type: "POST",
                url: "../admin/Order/GetDetailOrder",
                contentType: "application/json",
                data: data1,
                success: function (responseData) {
                    var ss = responseData
                    var tt = JSON.parse(ss);
                    $("#txtNosS").val(tt.oasno);
                    $("#txtPS").val(tt.toOGID.toString());
                    $("#txtRateS").val(tt.toTotalRate);
                    $("#txtDateS").val(tt.startDay);
                    $("#txtTimeS").val(tt.osaTimeslot);
                    $("#txtrichangS").val(tt.toTime);
                    $("#txtzhuanxiangS").val(tt.a);
                    $("#txtEndDateS").val(tt.endDay);

                    $("#txtStatus").val(tt.RowStatus.toString());
                    $("#spOrder").text(tt.toSerialNo);
                    closeLoading();
                }
            });
        }

        function updateOrder(){

            showLoading();
            var data1 = '{"orderid":"'+$("#spOrderID").text()+'","txtNos":"'+$("#txtNosS").val()+'","txtP":"'+$("#txtPS").val()+'","txtRate":"'+$("#txtRateS").val()+'","txtDate":"'+$("#txtDateS").val()+'","txtTime":"'+$("#txtTimeS").val()+'","txtrichang":"'+$("#txtrichangS").val()+'","txtzhuanxiang":"'+$("#txtzhuanxiangS").val()+'","txtEndDate":"'+$("#txtEndDateS").val()+'","txStatus":"'+$("#txtStatus").val()+'"}';

            $.ajax({
                type: "POST",
                url: "../admin/Order/UpdateOrder",
                contentType: "application/json",
                data: data1,
                success: function (responseData) {
                    window.location.href="../admin/Order";
                }
            });

        }

        function GoToContiun(){

            showLoading();
            var data1 = '{"orderid":"'+$("#spOrderID").text()+'","txtNos":"'+$("#txtNosS").val()+'","txtP":"'+$("#txtPS").val()+'","txtRate":"'+$("#txtRateS").val()+'","txtDate":"'+$("#txtDateS").val()+'","txtTime":"'+$("#txtTimeS").val()+'","txtrichang":"'+$("#txtrichangS").val()+'","txtzhuanxiang":"'+$("#txtzhuanxiangS").val()+'"}';

            $.ajax({
                type: "POST",
                url: "../admin/Order/GoToContiun",
                contentType: "application/json",
                data: data1,
                success: function (responseData) {
                    window.location.href="../admin/Order";
                }
            });

        }

        function deleteOrder(){

            showLoading();
            var data1 = '{"orderid":"'+$("#spOrderID").text()+'"}';
            $.ajax({
                type: "POST",
                url: "../admin/Order/RemoveOrder",
                contentType: "application/json",
                data: data1,
                success: function (responseData) {
                    window.location.href="../admin/Order";
                }
            });

        }


    </script>
}

